﻿using System;
using NUnit.Framework;
using SharpSvn;
using SvnFlow;

namespace SvnFlowTests
{
    [TestFixture]
    public class BranchInfoTests
    {
        [Test]
        public void TestCreate()
        {
            var branch = new BranchInfo(
                new Uri("file:///test_dir"), "test", "test/full/path", 
                new SvnRevisionRange(SvnRevision.Zero,1));

            Assert.That(branch.Name, Is.EqualTo("test"));
            Assert.That(branch.FullPath, Is.EqualTo("test/full/path"));
            Assert.That(branch.Uri, Is.EqualTo(new Uri("file:///test_dir")));
            Assert.That(branch.PrevRevision, Is.EqualTo(SvnRevision.Zero.Revision));
            Assert.That(branch.LastRevision, Is.EqualTo(1));
            Assert.That(branch.WorkingCopyRevision, Is.Null);

            Assert.That(() => branch.Range, Throws.TypeOf<InvalidOperationException>());
        }

        [Test]
        public void TestGetRange()
        {
            var branch = new BranchInfo(
                new Uri("file:///test_dir"), "test", "test/full/path", 
                new SvnRevisionRange(SvnRevision.Zero, 1)) { WorkingCopyRevision = 2 };

            var range = branch.Range;
            Assert.AreEqual(range.StartRevision.Revision, 1);
            Assert.AreEqual(range.EndRevision.Revision, 2);
        }

        [Test]
        public void TestUpdateRevisions()
        {
            var branch = new BranchInfo(
                new Uri("file:///test_dir"), "test", "test/full/path", 
                new SvnRevisionRange(SvnRevision.Zero, 1)) { WorkingCopyRevision = 2 };

            branch.UpdateRevisions();

            Assert.AreEqual(branch.PrevRevision, 1);
            Assert.AreEqual(branch.LastRevision, 2);
        }
    }
}
